package com.ddtech.framework.generator.service.impl;

import com.ddtech.framework.generator.model.SysGenConfig;
import com.ddtech.framework.generator.repository.GenConfigRepository;
import com.ddtech.framework.generator.service.GenConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author Apache License
 * @date 2019-01-14
 */
@Service
public class GenConfigServiceImpl implements GenConfigService {

    @Autowired
    private GenConfigRepository genConfigRepository;

    @Override
    public SysGenConfig find() {
        Optional<SysGenConfig> genConfig = genConfigRepository.findById("1");
        if(genConfig.isPresent()){
            return genConfig.get();
        } else {
            return new SysGenConfig();
        }
    }

    @Override
    public SysGenConfig update(SysGenConfig genConfig) {
        genConfig.setId("1");
        return genConfigRepository.save(genConfig);
    }
}
